package com.jiaofamily.localad.sdk.adapters;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

import com.jiaofamily.localad.sdk.obj.Ration;
import com.jiaofamily.localad.sdk.util.LocalAdUtil;

public class Count {
	public static void countShow(Context context, Ration activeRation){
		SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(context);
		Editor et;
		if(activeRation!=null){
			et=sp.edit();
			switch(activeRation.type){
			case LocalAdUtil.NETWORK_TYPE_YOUMI:
				et.putLong("showCountYoumi", sp.getLong("showCountYoumi", 0)+1);
				break;
			case LocalAdUtil.NETWORK_TYPE_WIYUN:
				et.putLong("showCountWiyun", sp.getLong("showCountWiyun", 0)+1);
				break;
			case LocalAdUtil.NETWORK_TYPE_ADMOB:
				et.putLong("showCountAdmob", sp.getLong("showCountAdmob", 0)+1);
				break;
			}
			et.commit();
			et.clear();

//			System.out.println("youmi="+sp.getLong("showCountYoumi",0)+"\t"+"weiyun="+sp.getLong("showCountWiyun", 0)
//					+"\t"+"admob="+sp.getLong("showCountAdmob", 0));
			
		}
	}
	
	public static void countClick(Context context, Ration activeRation){
		SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(context);
		Editor et;
		if(activeRation!=null){
			et=sp.edit();
			switch(activeRation.type){
			case LocalAdUtil.NETWORK_TYPE_YOUMI:
				et.putLong("clickCountYoumi", sp.getLong("clickCountYoumi", 0)+1);
				break;
			case LocalAdUtil.NETWORK_TYPE_WIYUN:
				et.putLong("clickCountWiyun", sp.getLong("clickCountWiyun", 0)+1);
				break;
			case LocalAdUtil.NETWORK_TYPE_ADMOB:
				et.putLong("clickCountAdmob", sp.getLong("clickCountAdmob", 0)+1);
				break;
			}
			et.commit();
			et.clear();

//			System.out.println("youmi="+sp.getLong("clickCountYoumi",0)+"\t"+"weiyun="+sp.getLong("clickCountWiyun", 0)
//					+"\t"+"admob="+sp.getLong("clickCountAdmob", 0));
			
		}
	}
}
